package com.epoint.mobileoa.tools;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.telephony.CellLocation;
import android.telephony.TelephonyManager;
import android.view.WindowManager;

/**
 * @author liyc
 * @time 2012-3-21 上午8:12:32
 * @annotation 
 */
public class PhoneHelp {

	/*    
	 * 电话状态：    
	 * 1.tm.CALL_STATE_IDLE=0          无活动    
	 * 2.tm.CALL_STATE_RINGING=1  响铃    
	 * 3.tm.CALL_STATE_OFFHOOK=2  摘机    
	 */ 
	public static int getCallState(Context con){
		TelephonyManager tm = (TelephonyManager) con.getSystemService(Context.TELEPHONY_SERVICE);
		return tm.getCallState();
	}

	/*    
	 * 电话方位：    
	 */ 
	public static CellLocation getCellLocation(Context con){
		TelephonyManager tm = (TelephonyManager) con.getSystemService(Context.TELEPHONY_SERVICE);
		return tm.getCellLocation();
	}

	/*    
	 * 唯一的设备ID：    
	 * GSM手机的 IMEI 和 CDMA手机的 MEID.     
	 * Return null if device ID is not available.    
	 */
	public static String getDeviceId(Context con){
		TelephonyManager tm = (TelephonyManager) con.getSystemService(Context.TELEPHONY_SERVICE);
		return tm.getDeviceId();
	}

	public static void sendMsgUsePhoneSelf(Context con,String phonenum,String body){
		Uri smsToUri = Uri.parse("smsto:"+phonenum);    
		Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );  
		mIntent.putExtra("sms_body", body);  
		con.startActivity( mIntent );
	}

	//调用系统浏览器
	public static void invokeSystemBrowser(Context con,String url){
		Intent intent= new Intent();        
		intent.setAction("android.intent.action.VIEW");    
		Uri content_url = Uri.parse(url);   
		intent.setData(content_url);  
		con.startActivity(intent);

		/*Uri u = Uri.parse(url);  

		Intent it = new Intent();

		it.setData(u);  

		it.setAction( Intent.ACTION_VIEW);  

		it.setClassName("com.android.browser","com.android.browser.BrowserActivity");  

		startActivity(it); */
	}

	//获取屏幕宽度
	public static int getPhoneWidth(Context con){
		WindowManager wm = (WindowManager)con.getSystemService(Context.WINDOW_SERVICE);
		return wm.getDefaultDisplay().getWidth();
	}

	//获取屏幕高度
	public static int getPhoneHeight(Context con){
		WindowManager wm = (WindowManager)con.getSystemService(Context.WINDOW_SERVICE);
		return wm.getDefaultDisplay().getHeight();
	}
}
